package com.azt.front.service.impl;

import com.azt.api.pojo.Category;
import com.azt.api.pojo.Content;
import com.azt.api.pojo.EnqEnquiry;
import com.azt.api.pojo.Product;
import com.azt.api.service.*;
import com.azt.front.service.SitemapService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 站点地图
 * Created by LiQZ on 2017/3/22.
 */
@Service
public class SitemapServiceImpl implements SitemapService {

    public static final Logger logger = LoggerFactory.getLogger(SitemapServiceImpl.class);

    @Autowired
    private ConfigService configService;

    @Autowired
    private ProductService productService;

    @Autowired
    private ContentService contentService;

    @Autowired
    private ProCategoryService proCategoryService;

    @Autowired
    private EnqEnquiryService enqEnquiryService;



    @Override
    public Map<String, Object> getParams(String type) {
        Map<String, Object> params = new HashMap<>();
        String webSite = configService.getConfigValueByCode("WEB_SITE");
        params.put("webSite", "http://" + webSite);
        switch (type) {
            case "product": return generatorProduct(params);
            case "category": return generatorCategory(params);
            case "information": return generatorInformation(params);
            case "enquiry": return generatorEnquiry(params);
        }
        return params;
    }

    private Map<String, Object> generatorProduct(Map<String, Object> params) {
        List<Product> products = productService.listProductIdAndTime(20000);
        params.put("products", products);
        return params;
    }

    private Map<String, Object> generatorCategory(Map<String, Object> params) {
        List<Category> categoryList = proCategoryService.listAllCategoryBySize(20000);
        params.put("categoryList", categoryList);
        return params;
    }

    private Map<String, Object> generatorInformation(Map<String, Object> params) {
        List<Content> infoList = contentService.listContentBySize(2000);
        params.put("infoList", infoList);
        return params;
    }

    private Map<String, Object> generatorEnquiry(Map<String, Object> params) {
        List<EnqEnquiry> enquiryList = enqEnquiryService.listEnquiryBySize(1000);
        params.put("enquiryList", enquiryList);
        return params;
    }
}
